package com.wingsoft.homeFlow.bo;

import com.wingsoft.common.exception.ServiceException;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

@Data
public class HomeFlowTaskVarBo {

    @ApiModelProperty("ID")
    private String id;

    @ApiModelProperty("任务编码")
    private String taskCode;

    @ApiModelProperty("步骤KEY")
    private String stepCode;

    @ApiModelProperty("变量编码")
    private String varCode;

    @ApiModelProperty("变量完整名")
    public String getVarCodeFull() {
        return StringUtils.isNotBlank(stepCode) ? (stepCode + "_" + varCode) : varCode;
    }

    @ApiModelProperty("变量名称")
    private String varName;

    @ApiModelProperty("变量取值路径")
    private String varPath;

    @ApiModelProperty("数据类型：1-单个；2-对象；3-集合；4-日期")
    private Integer dataType;

    @Getter
    @AllArgsConstructor
    public enum DataTypeEnum {
        SINGLE(1, "单个"),
        OBJECT(2, "对象"),
        COLLECTION(3, "集合"),
        DATE(4, "日期");
        private final Integer code;
        private final String desc;

        public static DataTypeEnum getEnumByCode(Integer code) {
            for (DataTypeEnum value : DataTypeEnum.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            throw new ServiceException("数据类型枚举值不存在: " + code);
        }
    }

    @ApiModelProperty("实际值")
    private Object varValue;

    @ApiModelProperty("默认值")
    private String defaultValue;

    @ApiModelProperty("是否全局：1-是 0-否")
    private Integer globalFlag;

    @ApiModelProperty("是否工作流参数：1-是 0-否")
    private Integer flowFlag;

    @ApiModelProperty("是否手动添加：1-是 0-否")
    private Integer manualFlag;

    @ApiModelProperty("参数顺序")
    private Integer varIndex;

    @ApiModelProperty("是否启用：1-是 0-否")
    private Integer isUsed;

    @ApiModelProperty("创建用户ID")
    private Long createUserId;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("修改用户ID")
    private Long updateUserId;

    @ApiModelProperty("修改时间")
    private Date updateTime;

}